package com.karl.loadingviews.headers;

import android.content.Context;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;

import com.karl.loading.loadings.MiLoadingView;
import com.karl.loadingviews.BaseHeaderView;
import com.karl.loadingviews.R;
import com.lcodecore.tkrefreshlayout.IHeaderView;
import com.lcodecore.tkrefreshlayout.OnAnimEndListener;

/**
 * Created by CoderFan on 2017/8/27.
 * desc
 */

public class MiHeaderView extends BaseHeaderView {

    private MiLoadingView miLoadingView;

    public MiHeaderView(@NonNull Context context) {
        this(context,null);
    }

    public MiHeaderView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    private void init(Context context){
        LayoutInflater.from(context).inflate(R.layout.header_mi,this);
        miLoadingView = findViewById(R.id.loading_mi);
        miLoadingView.setColor(Color.parseColor("#999999"));
    }

    @Override
    public View getView() {
        return this;
    }

    @Override
    public void onPullingDown(float fraction, float maxHeadHeight, float headHeight) {
        if (fraction < 1){
            miLoadingView.updateProgress(fraction);
        }else {
            miLoadingView.updateProgress(1);
        }
    }

    @Override
    public void onPullReleasing(float fraction, float maxHeadHeight, float headHeight) {
        if (fraction<1){
            miLoadingView.updateProgress(fraction);
        }
    }

    @Override
    public void startAnim(float maxHeadHeight, float headHeight) {
        miLoadingView.startAnim();
    }

    @Override
    public void onFinish(OnAnimEndListener animEndListener) {
        animEndListener.onAnimEnd();
    }

    @Override
    public void reset() {
        miLoadingView.stopAnim();
    }
}
